<?php
class FriendlinksAction extends CommonAction {
    public function __construct(){
		parent::__construct();
		
		$this->modelObject = D('Friendlinks');
    }
   
    public function index(){
		$thisPage = $this->pageInfo['p'] = I('p', 1);
		
		if($this->pageInfo['name'] = I('name', '')){
			$map['name'] = array('LIKE', '%'.$this->pageInfo['name'].'%');
		}
		
		if($this->pageInfo['status'] = I('status', '')){
			$map['status'] = $this->pageInfo['status'];
		}
		
		//获得列表
		$list = $this->modelObject->getPageList($map, $thisPage);
		
		//分页
		$page = $this->modelObject->buildPage($map, $thisPage);
		$this->assign('page',$page);
		
		session('pageInfo', $this->pageInfo);
		$this->assign('pageInfo', $this->pageInfo);
		$this->assign('list', $list);
		$this->display();
    }
	
	public function del(){
		$id = I('id', 0, 'intval');
		if($id){
			if($this->modelObject->deleteInfo($id)){
				$this->success('删除成功', U('index', session('pageInfo')));	
			}else{
				$this->error('删除失败!');
			}
		}else{
			$this->error('参数错误!');
		}
	}
	
	public function delAll(){
		$id = I('id', 0, 'intval');
		$idStr = implode(',', $id);
		if(!empty($idStr)){
			if($this->modelObject->deleteInfo($idStr)){
				$this->success('删除成功', U('index', session('pageInfo')));	
			}else{
				$this->error('删除失败!');
			}
		}else{
			$this->error('参数错误!');
		}
	}
}